package com.yanqu.road.server.logic.activity.condition.musicroom;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.ePlayerAttrType;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.AttributeModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;

import java.math.BigInteger;

public class MusicRoomMissionCondition extends BaseCondition {

    public MusicRoomMissionCondition(TaskConditionInfo taskConditionInfo, BaseTaskData baseTaskData, BigInteger value, Object initArgs) {
        super(taskConditionInfo, baseTaskData, value, initArgs);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.MusicRoomMission.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.MusicRoomMission.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        BigInteger param4 = taskConditionInfo.getParamList().get(3);
        return getValue().compareTo(param4) >= 0;
    }

    @Override
    protected void changeValue(Object object) {
//        int stageId = (int) object;
//        setValue(BigInteger.valueOf(stageId));
        initValue();
    }

    @Override
    public void initValue() {
        long stageId = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.MusicRoomStageId);
        setValue(BigInteger.valueOf(stageId));
    }
}
